/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ticketmaster.dao;

import ticketmaster.dataobject.ShippingMethod;
import java.sql.*;
import javax.sql.*;
import java.util.*;
import java.util.logging.*;
/**
 *
 * @author Xiaolong Xue
 */
public class ShippingMethodDAO extends BaseEntityDAO
{
    public ShippingMethodDAO()
    {
        // construct a ShippingMethodDAO object
    }

    /**
     * Insert a new ShippingMethod object into database
     * @param shippingMethod the new shippingMethod entity to be inserted
     * @return newly created shippingMethod ID, or  0 when error
     */
    public int insertShippingMethod(ShippingMethod shippingMethod)
    {
        return save(shippingMethod);
    }

    /**
     * Delete a ShippingMethod object that matches the supplied criteria
     * @param shippingMethod the supplied criteria
     * @return true if success, or false
     */
    public boolean deleteShippingMethod(ShippingMethod shippingMethod)
    {
        return delete(shippingMethod);
    }

    /**
     * Update the shippingMethod by using data from the ShippingMethod Data Object(from UI)
     * @param shippingMethod the ShippingMethod Data Object to be updated
     * @return true on success, false on failure or error
     */
    public boolean updateShippingMethod(ShippingMethod shippingMethod)
    {
        if(shippingMethod.getShippingMethodID() == 0)
            return false;
        if(update(shippingMethod))
            return true;
        else
            return false;
    }

    /**
     * Get the shippingMethod that matches the supplied criteria
     * @param shippingMethod the supplied criteria
     * @return a ShippingMethod Object if found, or null on error or if not found
     */
     public ShippingMethod findShippingMethod(ShippingMethod shippingMethod)
     {
         String sql = null;
         if(shippingMethod.getShippingMethodID() == 0)
             return null;
         else
             sql = buildQuerySQL(shippingMethod);

         RowSet srs = query(sql);

         try
         {
             srs.next();
         }
         catch(SQLException ex)
         {
             Logger.getLogger(ShippingMethodDAO.class.getName()).log(Level.SEVERE, null, ex);
         }

         return (ShippingMethod) this.getObject(srs, shippingMethod);
     }

    /**
     * Get all shippingMethod that match the supplied criteria
     * @param shippingMethod supplied criteria
     * @return a RowSet of shippingMethod
     */
     public RowSet getShippingMethodRowSet(ShippingMethod shippingMethod)
     {
         String sql = buildQuerySQL(shippingMethod);
         return query(sql);
     }

    /**
     * Get all shippingMethod that match the supplied criteria
     * @param shippingMethod supplied criteria
     * @return a collection of ShippingMethod Data Objects
     */
     public Collection<ShippingMethod> getShippingMethodDO(ShippingMethod shippingMethod)
     {
         String sql = buildQuerySQL(shippingMethod);
         RowSet srs = query(sql);
         Collection<ShippingMethod> shippingMethods = new ArrayList<ShippingMethod>();
         try
         {
             while(srs.next())
             {
                 ShippingMethod shippingMethodDO = (ShippingMethod) this.getObject(srs, shippingMethod);
                 ShippingMethod method = new ShippingMethod();
                 method.setName(shippingMethodDO.getName());
                 method.setPrice(shippingMethodDO.getPrice());
                 method.setShippingMethodID(shippingMethodDO.getShippingMethodID());
                 shippingMethods.add(method);
             }
         }
         catch(SQLException ex)
         {
            Logger.getLogger(ShippingMethod.class.getName()).log(Level.SEVERE, null, ex);
         }

         return shippingMethods;
     }
}
